home *** CD-ROM | disk | FTP | other *** search
- From: Roly Perera <rolyp@private.nethead.co.uk>
- Message-ID: <3122614B.520C@private.nethead.co.uk>
- X-Original-Date: Wed, 14 Feb 1996 22:25:15 +0000
- Path: in2.uu.net!bounce-back
- Date: 15 Feb 96 11:59:55 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: deriving from a typedef name
- Organization: Gnosis
- References: <4fdinq$8ds@cnn.Princeton.EDU>
- X-Mailer: Mozilla 2.0 (Win95; I)
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMSMhAeEDnX0m9pzZAQE4xQF/VGUezVx7nL8hH1AQx5khx4obhi4Esf+h
- QkgMiZBf827v+fIfv/np3+c4hOAzYfwD
- =Kp/5
-
- tim@franck.Princeton.EDU (Tim Hollebeek) wrote:
-
- > I suspect this is correct behavior, but it sure is confusing, so I
- > thought I'd double check:
- >
- > template <class T>
- > class nVector {
- > };
- >
- > typedef nVector<double> Vector; // workaround for compiler that
- > // doesn't handle <class T = double> >
- >
- > class Point : public Vector { // derive from typedef name
- > public:
- > Point(const Vector& v) { Vector::Vector(v); } // ***
- > };
- >
- > At ***, I get: test.C:9: no method `nVector<double>::Vector'
- > for obvious reasons. However, it's not so obvious if you are just
- > looking at the declaration of class Point, and the alternatives:
-
- The reason that 'Vector::Vector(v)' doesn't work is not that Vector is a
- typedef. In fact for most (all?) purposes, the typedef name is as good
- as a class. The problem is that the way to explicitly call a
- constructor is by using the name of the constructor *unqualified* by the
- scope of the class. It's as though the constructor were defined in
- namespace enclosing the class, rather than that of the class itself. So
- for a normal member function, you call it by qualifying it by the class
- name (Vector::insert), but for a constructor, you refer to it just by
- its name (Vector). Your example would work with:
- Point (const Vector& v) { Vector(v); }
- although this will just create a temporary variable, initialise it, and
- then discard it (as your original code would do too, if it worked).
-
- > Vector::nVector<double>(v); // parse error
- > nVector<double>::nVector<double>(v); // parse error
-
- Same applies. Simply 'nVector<double>(v);' would be sufficient. Again,
- such code is pointless unless nVector<double>'s copy constructor has
- side effects.
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. Moderation policy:
- http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
-